ChkBugReport工具 for Android 1

BugReport

Android 的 BugReport 一般是 .txt 结尾的文本文件,也有可能是 .log。当然了,命名没有限定。不要慌实质是一样的,就全部当成 .txt
获取BugReport文件:adb bugreport > bugreport.txt

ChkBugReport介绍

关于这个工具,找到的资料都比较旧了,貌似是索尼移动的开发人员开发的,2014年左右的文章比较多,应该是那个时候索尼移动还是比较鼎盛的时期吧。现在已经很少看到关于这个工具的文章了,应该是工具比较稳定健壮了,不需要太大的修改量了。

官方网站:http://developer.sonymobile.com/knowledge-base/tools/analyse-your-bugreports-with-our-open-source-tool/

开源地址:https://github.com/sonyxperiadev/ChkBugReport

官网是这样介绍的

ChkBugReport is a new bugreport analysis tools released as open source .
下面一段翻译自这里:安卓的开发者们,你们还在为经常碰到的ANR而感到头疼和不爽么,还在为应用崩溃而抓耳挠腮么?还在因为收集到的错误日志杂乱无章而感到束手无策么?ChkBugReport将为你解忧愁,解心宽,解决各种小困难。ChkBugReport,简单易用,简直是居家旅行,工作生活必备之良品。

ChkBugReport 开源工具

ChkBugReport是一个开源工具,它可以把你得到的bugreprot解析成适合阅读的html文件。导出的html文件包含了根据bugreport数据得出的图表和分析结论。

它的源码中用到了以下开源类库: jQuery ,jsTree jQuery plugin , tablednd jQuery plugin , tablesorter jQuery plugin ,js-hotkeys, jquery-cookie 。学习输出报告文档型html可以参考源码。

目前ChkBugReport可以从bugreport数据中抽取出如下信息:

  1. Stacktraces ChkBugReport可以从bugreport中解析出输出bugreport的最后时刻、导致ANR时刻甚至更多时刻的堆栈信息。在例子中你可以看到进程的优先级和策略都已标示出来,堆栈中耗时的部分颜色是黑红,一些违反Strict Mode的部分(比如主线程中使用数据库)颜色标记为亮红。如果这个线程死锁,在报告的Errors将会出现。
  2. Logs 这部分是对system、main和kernel日志的分析,在这里你可以看到每个进程内存使用图、那个程序产生的log最多、Activity的启动耗时、数据库操作耗时统计、对象被锁定时间、AIDL调用时间、Activity和Service的生命周期及其在内存中使用频率等等,详见
  3. Packages ChkBugReport解析bugreport中存储的packages.xml并展示一系列的packages、user ids和 permissions。参见
  4. Processes 操作app过程中产生的系统事件日志、内存使用信息等等,参见
  5. Battery statistics 电池使用统计信息,参见
  6. CPU Frequency statistics CPU频率统计信息,参见
  7. Raw data 被分割成小段的原始数据

同时ChkBugReport也可以检测到(潜在的)错误,这些错误在输出的报告Errors部分中可以找到。你也可以在输出报告的stacktrace中找到死锁或一些违反Strict Mode的行为。

ChkBugReport使用

github上 How to use it

java -jar $HOME/chkbugreport.jar $HOME/bugreport.txt
$HOME 是一个环境变量,chkbugreport.jar目录的路径。

    ChkBugReport 会为你生成一个文件夹,叫做 bugreport_out,文件夹里有个 index.html 文件,这就是我们的错误报告的网页了,是一个 HTML 文件。

    你可以双击启动它 (如果你设置了 .html 文件用浏览器程序启动的话), 或者用命令行,比如我用 firefox 浏览器来启动这个 HTML 文件:

firefox bugreport_out/index.html

命令参数

Command-line-options

For a complete list of parameters just run the tool without any arguments. As of now the following parameters are handled:

  • -ds:file - Use file as dumsys output (almost same as -pb)
  • -el:file - Use file as event log
  • -ft:file - Use file as ftrace dump
  • -ml:file - Use file as main log
  • -mo:file - Parse monkey output and extract stacktraces from it
  • -pb:file - Load partial bugreport (eg. output of dumpsys)
  • -pk:file - Load packages.xml file
  • -ps:file - Use file as “processes” section
  • -pt:file - Use file as “processes and threads” section
  • -sa:file - Use file as “vm traces at last anr” section
  • -sl:file - Use file as system log
  • -sn:file - Use file as “vm traces just now” section
  • -sd:dir - Load files from directory as partial bugreports
  • -uh:file - Load usage-history.xml file

Extra options (less frequently needed):

  • –browser - Launch the browser when done
  • –gui - Launch the Graphical User Interface if no file name is provided
  • –silent - Supress all output except fatal errors
  • –limit - Limit the input file size (default) If using the -sl option for example, the log file will be truncated if it’s too long (since the generated html would be even bigger). This option (and –no-limit as well) must precede the other options in order to have effect.
  • –no-limit - Don’t limit the input file size

NOTE: The graphical user interface is still experimental and very rudimentary

快捷方式


shell脚本

创建一个 chkbugreport 的 Shell 脚本,放在 $HOME/bin 目录中 :

vim $HOME/bin/chkbugreport

在脚本中加入以下代码:

#!/bin/sh

DIR=$HOME/bin
JAR=$DIR/chkbugreport-0.4-185.jar
CP=$JARif [ ! -f $JAR]; thenecho"为了这个脚本能够运行,请把下载的 ChkBugReport 的 JAR 包拷贝到 $JAR 中"exit 1
fi

java -jar $CP"$@"

为脚本添加可执行权限:

chmod +x $HOME/bin/chkbugreport

确保 $HOME/bin 这个目录在 Path 环境变量中,请参看 Linux探索之旅 | 第五部分第二课:一入Shell深似海,酷炫外壳惹人爱

之后,cmd中运行

chkbugreportbugreport.txt

bat脚本

创建一个 chkbugreport.bat 的 bat 脚本,把 chkbugreport.bat 的路径加到环境变量中。在脚本中加入以下代码:

@echo off

java -jar E:\Android\chkbugreport\chkbugreport-0.4-185.jar %1

之后,cmd中运行

chkbugreport "bugreport.txt"

chkbugreport 报错

C:\Users\Administrator>chkbugreport C:\Users\Administrator\Desktop\download@tid[]=4573872\4573872_20
18-11-19-064158-3908515\bugreport_1542589813841.txt
WTChkBugReport 0.5 (rev 216) !!BASE ON ChkBugReport!!
Failed to load plugin: com.sonyericsson.chkbugreport.AdbExtension
File C:\Users\Administrator\Desktop\download@tid[] does not exists!
Cannot open file: C:\Users\Administrator\Desktop\download@tid[]

注意:Windows 上最好添加双引号 chkbugreport “… …\bugreport.txt”


参考文献

Android神兵利器 | ChkBugReport输出网页版错误报告
ChkBugReport工具for Android
android 使用开源工具ChkBugReport分析Bugreport

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×